/*************************************************************************
	> File Name: oj-264.cpp
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2021年01月10日 星期日 16时23分20秒
 ************************************************************************/
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX_N 100000
long long s[MAX_N +5], t;
long long h[MAX_N + 5], n;
long long l[MAX_N +5], r[MAX_N + 5];

long long solve();

long long main() {
    scanf("%lld", &n);
    for (long long i = 1; i <= n; ++i) {
        scanf("%lld", &h[i]);
    }
    printf("%lld", solve());
    return 0;
}

long long solve() {
    h[0] = h[n + 1] = -1;
    t = -1;
    s[++t] = 0;
    for (long long i = 1; i <= n; ++i) {
        while (t != -1 && h[s[t]] >= h[i]) --t;
        l[i] = s[t];
        s[++t] = i;
    }
    t = -1;
    s[++t] = 0;
    for (long long i = n; i >= 1; --i) {
        while (t != -1 && h[s[t]] >= h[i]) --t;
        r[i] = s[t];
        s[++t] = i;
    }
    long long ans = 0;
    for (long long i = 1; i <= n; ++i) {
        ans = max(ans, h[i] * (r[i] - l[i] - 1));
    }
    return ans;
}
